<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <ul class="list">
        <li></li>
    </ul>
    <button>获取电影</button>
    <button>添加电影</button>
    <button>修改电影</button>
    <button>局部修改</button>
    <button>删除电影</button>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');
        
        btns[0].onclick =async function(){
            let {data} = await axios('http://localhost:3000/movies');
            let str = ``;
            data.forEach(item => {
                str += `<li>${item.name}</li>`;
            });

            ul.innerHTML = str;
        }
    
        btns[1].onclick =async function(){
           let res =await axios('http://localhost:3000/movies',{
                method:"post",
                data:{
                    name:"四大名著",
                    director:"王宁",
                    star:"刘强"
                }
            });

            console.log(res);
        }
    
        btns[2].onclick =async function(){
           let res = await axios('http://localhost:3000/movies/8',{
                method:"put",
                data:{
                    name:"红楼梦"
                }
            })

            console.log(res);
        }
    
        btns[3].onclick =async function(){
            axios('http://localhost:3000/movies/7',{
                method:"patch",
                data:{
                    star:"刘强老师"
                }
            })
        }
    
        btns[4].onclick =async function(){
            let res = await axios('http://localhost:3000/movies/8',{
                method:"delete"
            })
            console.log(res);
        }

    </script>
</body>

</html>